from pynput import keyboard
from pynput.mouse import Controller
import pyautogui
from threading import Thread
import tkinter as tk
import sys


class MainWindows(tk.Tk):
    def __init__(self):
        super().__init__()
        self.wm_attributes('-topmost', 0)
        self.overrideredirect(True)
        sw =self.winfo_screenwidth()
        sh =self.winfo_screenheight()
        ww = 200
        wh = 100
        self.geometry("%dx%d+%d+%d" % (ww, wh, (sw - ww) / 2, (sh - wh) / 2 ))
        self.after(1, lambda:self.focus_force())
        self.input = tk.StringVar()
        self.pixels = tk.StringVar()
        self.hint = tk.StringVar()
        tk.Label(self, textvariable=self.pixels).pack()
        tk.Label(self, textvariable=self.hint).pack()
        self.entry = tk.Entry(self, textvariable=self.input)
        self.entry.bind('<Control-Key-e>',self.patient_info)
        self.entry.bind('<Enter>',self.ok)
        
        self.entry.pack()
    def patient_info(self, event):
        pass
    def ok(self, event):
        self.destroy()
def on_activate():
    
    app = MainWindows()
    app.mainloop()
    

class ListenThread(Thread):  # 截屏监听线程，监听函数一定要放在后台线程
    '''
        func_hotkey_map: dict {'<ctrl>+k': func_name}
        eg:
        {'<ctrl>+k': on_activate_screenshot,
        '<alt>+x': on_activate_ocr,
        '<alt>+c': on_activate_screenrecord,
        'z+x': on_activate_actionrun,
        'c+x': on_activate_actionrecord,}
    '''
    def __init__(self, func_hotkey_map):
        
        super().__init__()
        self.func_hotkey_map = func_hotkey_map
    def run(self):
        
        hotkey = keyboard.GlobalHotKeys(self.func_hotkey_map)

        hotkey.start()
        hotkey.wait()
        hotkey.join()


if __name__ == "__main__":
    
    listenThread = ListenThread({
        '<ctrl>+k':on_activate
        })  # 创建监听线程
    listenThread.start()
    
    
    
    
